<template>
  <goods-order ref="goodsOrder"></goods-order>
</template>

<script>
  import GoodsOrder from 'views/goodsOrder';

  import HistoryUtil from 'utils/historyUtil';

  export default {
    data() {
      return {
        paySuccess: false,
        evalSuccess: false
      };
    },

    created() {
      window.unReloadStatus = true;
      wx.hideShareMenu();

      window.toPaymentSuccess = () => {
        this.paySuccess = true;
        return window.Promise.resolve(true);
      }

      window.toEvalSuccess = () => {
        this.evalSuccess = true;
      }

      window.addEventListener('pulldownrefresh', () => {
        this.$refs['goodsOrder'].resetOrderList(false, '刷新中...').then(() => {
          wx.stopPullDownRefresh();
        });
      });

      window.addEventListener('wxshow', () => {
        HistoryUtil.clear();

        if (this.paySuccess) {
          this.paySuccess = false;
          this.$refs['goodsOrder'].resetOrderList(true);
        } else if (this.evalSuccess) {
          this.evalSuccess = false;
          this.$refs['goodsOrder'].resetOrderList(true);
        }
      });
    },

    components: {
      GoodsOrder
    }
  };

</script>
